package tzy.scrollview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import static android.support.v4.view.ViewCompat.TYPE_NON_TOUCH;

/**
 * Created by Administrator on 2018/5/7.
 */

public class CustomNestedScrollView2 extends CustomNestedScrollView {

    public CustomNestedScrollView2(Context context) {
        super(context);
    }

    public CustomNestedScrollView2(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomNestedScrollView2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    View mNestedScrollChild;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (mNestedScrollChild != null) {
            if (mNestedScrollChild instanceof RecyclerView) {
                ((RecyclerView) mNestedScrollChild).stopScroll();
            }
            mNestedScrollChild = null;
        }
        return super.onInterceptTouchEvent(ev);
    }


    @Override
    public void onStopNestedScroll(@NonNull View target, int type) {
        super.onStopNestedScroll(target, type);
        mNestedScrollChild = null;
    }


    @Override
    public void onNestedPreScroll(@NonNull View target, int dx, int dy, @Nullable int[] consumed, int type) {
        if (type == TYPE_NON_TOUCH) {
            mNestedScrollChild = target;
        }
        super.onNestedPreScroll(target, dx, dy, consumed, type);

    }


}
